﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Vulild.AopDecoration
{
    public class AopFilterCollection : IList<IAopFilter>, IAopFilter
    {
        List<IAopFilter> filters = new List<IAopFilter>();
        public IAopFilter this[int index] { get => filters[index]; set => filters[index] = value; }

        public int Count => filters.Count;

        public bool IsReadOnly => false;

        public void Add(IAopFilter item) => filters.Add(item);

        public void Clear() => filters.Clear();

        public bool Contains(IAopFilter item) => filters.Contains(item);

        public void CopyTo(IAopFilter[] array, int arrayIndex) => filters.CopyTo(array, arrayIndex);

        public IEnumerator<IAopFilter> GetEnumerator() => filters.GetEnumerator();

        public int IndexOf(IAopFilter item) => filters.IndexOf(item);

        public void Insert(int index, IAopFilter item) => filters.Insert(index, item);

        public bool Remove(IAopFilter item) => filters.Remove(item);

        public void RemoveAt(int index) => filters.RemoveAt(index);

        IEnumerator IEnumerable.GetEnumerator() => filters.GetEnumerator();

        public void Execute<T>(AopContext<T> context)
        {
            foreach (var filter in filters)
            {
                filter.Execute(context);
            }
        }
    }
}
